﻿using System;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace LNet.Learning.EF.DAL.Test
{
    [TestClass]
    public class UnitTest1
    {
        [TestMethod]
        public void TestMethodAdd()
        {
            using (Model1Container db = new Model1Container())
            {
                var user = new User()
                {
                    Id = Guid.NewGuid(),
                    Code = "liyb",
                    Name = "李永博",
                    Password = "123456"
                };
                db.UserSet.Add(user);
                db.SaveChanges();

                Assert.AreEqual(1, db.UserSet.Count());
            }
        }

        [TestMethod]
        public void TestMethodEdit()
        {
            using (Model1Container db = new Model1Container())
            {
                var liyb = db.UserSet.Single(k => k.Code == "liyb");

                var user = new User()
                {
                    Id = liyb.Id,
                    Code = "liyb",
                    Name = "李永博",
                    Password = "@@@@@@"
                };
                //db.Entry<User>(user).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();

                Assert.AreEqual(1, db.UserSet.Count());
            }
        }
    }
}
